import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/login',
    name: 'login',
    component: () => import('@/components/login.vue')
  },
  {
    path:'/',
    redirect:'/login'
  },
  {
    path: '/home',
    name: 'home',
    component: () => import('@/components/index/home.vue'),
    children:[
      {
        path: '/users',
        name: 'User',
        component: () => import('@/components/user/User.vue')
    },
      {
        path: '/roles',
        name: 'roles',
        component: () => import('@/components/Authority/roles.vue')
    },
      {
        path: '/rights',
        name: 'rights',
        component: () => import('@/components/Authority/rights.vue')
    },
    {
      path: '/goods',
      name: 'goods',
      component: () => import('@/components/good/goods.vue')
  },
  {
    path: '/getadd',
    name: 'getadd',
    component: () => import('@/components/good/getadd.vue')
},
    {
      path: '/reports',
      name: 'reports',
      component: () => import('@/components/report/reports.vue')
  },
    {
       path: "/categories",  
       name: 'categories',
      component: () => import('@/components/good/categories.vue')
      },
      {
        path:"/params",
        name:"params",
        component: () => import('@/components/good/params.vue')
      },
      {
        path:"/orders",
        name:"orders",
        component: () => import('@/components/order/orders.vue')
      }

    ],

    beforeEnter: (to, from, next) => {
      console.log(to)
      if(!sessionStorage.getItem("loginmsg")){
        alert("请先登录")
        next("/login")
      }else{
        next()
      }
    }
  }
]

const router = new VueRouter({
  routes
})

export default router
